
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[v_tb_poscancelvoucher]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[v_tb_poscancelvoucher]
GO

/****** Object:  View [dbo].[v_tb_poscancelvoucher]    Script Date: 10/17/2017 17:08:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




create  view [dbo].[v_tb_poscancelvoucher]
as

select cast(0 as bit) choice,m.bid m_bid,m.bdate m_bdate,m.bcode m_bcode,m.bkind m_bkind,m.bstate m_bstate,m.voucherid m_voucherid,m.remark m_remark,m.filid m_filid,m.deptid m_deptid,m.modifierid m_modifierid,m.create_by m_create_by,m.custom1 m_custom1,m.custom2 m_custom2,m.custom3 m_custom3,m.custom4 m_custom4,m.custom5 m_custom5,
  m.custom6 m_custom6,m.custom7 m_custom7,m.custom8 m_custom8,m.custom9 m_custom9,m.custom10 m_custom10,
  m.custom11 m_custom11,m.custom12 m_custom12,m.custom13 m_custom13,m.custom14 m_custom14,m.custom15 m_custom15,d.*
from tb_poscancelvoucher m left join (select ROW_NUMBER() over (partition by bid order by bno) as bdtlno,* from tb_poscancelvoucherdtl) d on m.bid=d.bid

GO




